package com.mapbox.maps.testapp.integration.surface

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mapbox.maps.testapp.examples.SimpleMapActivity
import com.mapbox.maps.testapp.examples.TextureViewActivity
import com.mapbox.maps.testapp.integration.BaseIntegrationTest
import com.mapbox.maps.testapp.integration.launchActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Regression test that validates reopening an Activity with a SurfaceView
 */
@RunWith(AndroidJUnit4::class)
class SurfaceViewReopenTest : BaseIntegrationTest() {

  @get:Rule
  var activityRule: ActivityScenarioRule<SimpleMapActivity> = ActivityScenarioRule(
    SimpleMapActivity::class.java
  )

  @Test
  @LargeTest
  fun reopenSurfaceViewActivity() {
    for (i in 0 until testRepeatCount) {
      device.waitForIdle()
      device.pressHome()
      device.waitForIdle()
      activityRule.scenario.onActivity {
        device.launchActivity(it, TextureViewActivity::class.java)
        device.waitForIdle()
      }
    }
  }
}